package com.yunhai.xc.permission.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yunhai.xc.permission.persistence.PermissionMapper;
import com.yunhai.xc.permission.persistence.RolePermissionMapper;
import com.yunhai.xc.role.persistence.RoleMapper;

@Service
public class PermissionService {

	@Autowired
	private RoleMapper roleMapper;
	@Autowired
	private RolePermissionMapper rolePermissionMapper;

	@Autowired
	private PermissionMapper permissionMapper;

	public List<String> getPermissions(Integer uid) {
		// uid-rid-pid--pcode 用户多角色 角色多资源
		List<Integer> roleId = roleMapper.getRoleId(uid);
		List<Integer> listPid = new ArrayList<>();
		for (Integer integer : roleId) {
			List<Integer> pid = rolePermissionMapper.getPid(integer);
			listPid.addAll(pid);
		}
		List<String> pcode = new ArrayList<>();
		for (Integer integer : listPid) {
			String code = permissionMapper.getPcode(integer);
			pcode.add(code);
		}
		return pcode;
	}

}
